package com.sky.mapper;

import com.sky.annotation.AutoFill;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface DishMapper {

    /**
     * 根据分类id查询菜品数量
     * @param categoryId
     * @return
     */
    @Select("select count(id) from sky_take_out.dish where category_id = #{categoryId}")
    Integer countByCategoryId(Long categoryId);


    /*
    * 添加菜品数据
    * */
    @AutoFill(value = OperationType.INSERT)
    @Options(useGeneratedKeys = true, keyProperty = "id")//添加菜品后返回菜品id
    @Insert("insert into sky_take_out.dish" +
            " (name, category_id, price, image, description,status, create_time, update_time, create_user, update_user) values" +
            " (#{name}, #{categoryId}, #{price},#{image},#{description}, #{status}, #{createTime}, #{updateTime}, #{createUser}, #{updateUser})")
    void insert(Dish dish);

    /*
    * 菜品分页查询
    * */
    List<DishVO> pageQuery(DishPageQueryDTO dishPageQueryDTO);

    /*
    * 根据id查询菜品
    * */
    @Select("select * from sky_take_out.dish where id = #{id}")
    Dish getById(Long id);

    /*
    *根据id删除菜品
    * */
    @Delete("delete from sky_take_out.dish where id = #{id}")
    void deleteById(Long id);

    /*
    *
    * */
    @AutoFill(value = OperationType.UPDATE)
    @Update("update sky_take_out.dish set " +
            "name = #{name}, category_id = #{categoryId}, price = #{price}, image = #{image}, description = #{description}, status = #{status}, update_time = #{updateTime}, update_user = #{updateUser} where id = #{id}")
    void update(Dish dish);

    /*
    * 根据菜品id来查询菜品信息及菜品口味
    * */
    DishVO getByIdWithFlavor(Long id);

    /*
    * 根据分类id查询菜品数据
    * */
    List<Dish> list(Dish dish);

    /**
     * 根据条件统计菜品数量
     * @param map
     * @return
     */
    Integer countByMap(Map map);


}
